package com.qqtech.qquan.hi.controller;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.common.annotation.VisitAnnt;
import com.qqtech.core.common.enums.RespEnum;
import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.hi.model.HiRuleResult;
import com.qqtech.qquan.hi.model.HiRuleResultQuery;
import com.qqtech.qquan.hi.model.HiRuleResultVo;
import com.qqtech.qquan.hi.service.HiRuleResultService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/hi/rule/result")
public class HiRuleResultController extends BaseWebController<HiRuleResult, HiRuleResultQuery> {
	@Resource
	private HiRuleResultService hiRuleResultService;
    
	@Override
	protected BaseService<HiRuleResult> getBaseService() {
		return hiRuleResultService;
	}
	
	/**
	 * 分页
	 * 
	 * @param hiRuleResultQuery
	 * @return
	 */
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/page")
	@ResponseBody
	public Result page(@RequestBody HiRuleResultQuery hiRuleResultQuery) {
		Result ret = new Result();
		Timestamp searchETime = hiRuleResultQuery.getEndAt();
		if (searchETime != null) {
			hiRuleResultQuery.setEndAt(TimeUtil.addDays(searchETime, 1));
		}
		Integer curUserId = super.getUserId();
		hiRuleResultQuery.setUserId(curUserId);
		Pageable pageKit = new PageKit(hiRuleResultQuery.getPage(), new PageOrder(Direction.DESC, "id"));
		Page<HiRuleResultVo> page = hiRuleResultService.queryPageList(hiRuleResultQuery, pageKit);
		ret.put("page", page);
		return ret;
	}
}
